#ifndef ABC_COMMON_H
#define ABC_COMMON_H

#include "libabckit/c/abckit.h"
#include "libabckit/c/extensions/arkts/metadata_arkts.h"
#include "libabckit/c/ir_core.h"
#include "libabckit/c/isa/isa_dynamic.h"
#include "libabckit/c/metadata_core.h"
#include "libabckit/c/statuses.h"
#include <cctype>
#include <cstring>
#include <fcntl.h>
#include <functional>
#include <iostream>
#include <memory>
#include <string_view>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <vector>

using namespace std;

// 验证 FILE_PATH 是否定义
#ifdef FILE_PATH
constexpr string_view abcPath = FILE_PATH;
#else
#error "FILE_PATH is not defined!"
#endif

#ifdef OUT_FILE_PATH
constexpr string_view outAbcPath = OUT_FILE_PATH;
#else
#error "OUT_FILE_PATH is not defined!"
#endif

auto g_impl = AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
auto g_implI = AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
auto g_implM = AbckitGetModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
auto g_implArkI = AbckitGetArktsInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
auto g_implArkM = AbckitGetArktsModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
auto g_implG = AbckitGetGraphApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
auto g_dynG = AbckitGetIsaApiDynamicImpl(ABCKIT_VERSION_RELEASE_1_0_0);

struct AbcEntityInfo
{
    std::string parentFuncName;
    std::string parentNamespaceName = "";
    std::string className = "";
    std::string path = "";
    std::string moduleName = "";
};

// 类型定义
struct AbcFunction
{
    AbckitCoreFunction *func = nullptr;
    bool isAnonymous = false;
    std::string funcName = "";
    std::string apiModuleName = ""; // @kit api
    std::string apiImportName = ""; // button
    std::string apiFuncName = "";   // onClick
    AbcEntityInfo entityInfo;
};

struct AbcClass
{
    AbckitCoreClass *cls = nullptr;
    vector<std::shared_ptr<AbcFunction>> funcList;
    AbcEntityInfo entityInfo;
};

struct AbcModule
{
    vector<std::shared_ptr<AbcClass>> classList;
    AbckitJsImportDescriptor *importDescriptor = nullptr;
    vector<std::shared_ptr<AbcFunction>> funcList;
    AbckitCoreModule *module = nullptr;
    AbcEntityInfo entityInfo;
};

struct AbcFile
{
    AbckitFile *file = nullptr;
    vector<std::shared_ptr<AbcModule>> moduleList;
};

#endif // ABC_COMMON_H